using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class OrderSummaryMap : EntityTypeConfiguration<OrderSummary>
    {
        public OrderSummaryMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .HasMaxLength(20);

            this.Property(t => t.Description)
                .HasMaxLength(500);

            this.Property(t => t.Evaluation1)
                .HasMaxLength(500);

            this.Property(t => t.Evaluation2)
                .HasMaxLength(500);

            this.Property(t => t.Note)
                .HasMaxLength(500);

            // Table & Column Mappings
            this.ToTable("OrderSummary");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.OrderID).HasColumnName("OrderID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.StartDate).HasColumnName("StartDate");
            this.Property(t => t.EndDate).HasColumnName("EndDate");
            this.Property(t => t.ProductModelID).HasColumnName("ProductModelID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.TotalCost).HasColumnName("TotalCost");
            this.Property(t => t.UnitPrice).HasColumnName("UnitPrice");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.ExaminerID).HasColumnName("ExaminerID");
            this.Property(t => t.Evaluation1).HasColumnName("Evaluation1");
            this.Property(t => t.Evaluation2).HasColumnName("Evaluation2");
            this.Property(t => t.Note).HasColumnName("Note");
            this.Property(t => t.OrderProcessID).HasColumnName("OrderProcessID");
            this.Property(t => t.Status).HasColumnName("Status");

            // Relationships
            this.HasOptional(t => t.Employee)
                .WithMany(t => t.OrderSummaries)
                .HasForeignKey(d => d.ExaminerID);
            this.HasOptional(t => t.Order)
                .WithMany(t => t.OrderSummaries)
                .HasForeignKey(d => d.OrderID);
            this.HasOptional(t => t.ProductModel)
                .WithMany(t => t.OrderSummaries)
                .HasForeignKey(d => d.ProductModelID);

        }
    }
}
